﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SMS.Domain;
using SMS.Shell.Windows;
using SMS.Domain.Model;

namespace SMS.Shell.Views
{
    /// <summary>
    /// Interaction logic for CargoListView.xaml
    /// </summary>
    public partial class CargoListView : Page
    {
        public CargoListView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(CargoListView_Loaded);
        }

        void CargoListView_Loaded(object sender, RoutedEventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            _gridCargo.ItemsSource = new SmsService().FindCargos();
        }

        private void _btnCreate_Click(object sender, RoutedEventArgs e)
        {
            if (new CargoWindow().ShowDialog() == true)
            {
                LoadData();
            }
        }

        private void _btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            Cargo cargo = _gridCargo.SelectedItem as Cargo;
            if (cargo != null)
            {
                if (new CargoWindow(cargo).ShowDialog() == true)
                {
                    LoadData();
                }
            }
        }
    }
}
